﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using LibHuman;

namespace Human
{
	/// <summary>
	/// Summary description for frmLyLichDaoTaoGiaCanh.
	/// </summary>
	public class frmLyLichDaoTaoGiaCanh : System.Windows.Forms.Form
	{
        private AccessData mDB = new AccessData();
        Language lan = new Language();
		private DataSet ds =new DataSet();
        string m_user="",s_bophan="",user_dn="";		
		private DataSet dsxml=new DataSet();
        DataSet ds_lst = new DataSet();
        private System.Windows.Forms.Button butThoat;
		private System.Windows.Forms.Button butIn;
		private System.Windows.Forms.Button butXem;
        public System.Windows.Forms.DataGrid dgrXemLyLich;
        private LibList.List lst_lylich;
        private Label label5;
        private Label label4;
        private TextBox txt_hoten;
        private TextBox txt_manv;
        private ToolTip tl_manv;
        private Label label1;
        private IContainer components;

		public frmLyLichDaoTaoGiaCanh(string s_makp,string s_userdn)
		{
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
            s_bophan = s_makp;
            user_dn = s_userdn;
		}
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmLyLichDaoTaoGiaCanh));
            this.butThoat = new System.Windows.Forms.Button();
            this.butIn = new System.Windows.Forms.Button();
            this.butXem = new System.Windows.Forms.Button();
            this.dgrXemLyLich = new System.Windows.Forms.DataGrid();
            this.label5 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.txt_hoten = new System.Windows.Forms.TextBox();
            this.txt_manv = new System.Windows.Forms.TextBox();
            this.lst_lylich = new LibList.List();
            this.tl_manv = new System.Windows.Forms.ToolTip(this.components);
            this.label1 = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.dgrXemLyLich)).BeginInit();
            this.SuspendLayout();
            // 
            // butThoat
            // 
            this.butThoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butThoat.Image = global::Human.Properties.Resources.close_r;
            this.butThoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butThoat.Location = new System.Drawing.Point(211, 110);
            this.butThoat.Name = "butThoat";
            this.butThoat.Size = new System.Drawing.Size(60, 28);
            this.butThoat.TabIndex = 4;
            this.butThoat.Text = "Thoát";
            this.butThoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butThoat.Click += new System.EventHandler(this.butThoat_Click);
            // 
            // butIn
            // 
            this.butIn.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butIn.Image = global::Human.Properties.Resources.t_printer;
            this.butIn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butIn.Location = new System.Drawing.Point(145, 110);
            this.butIn.Name = "butIn";
            this.butIn.Size = new System.Drawing.Size(60, 28);
            this.butIn.TabIndex = 3;
            this.butIn.Text = "In";
            this.butIn.Click += new System.EventHandler(this.butIn_Click);
            // 
            // butXem
            // 
            this.butXem.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butXem.Image = global::Human.Properties.Resources.t_search;
            this.butXem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butXem.Location = new System.Drawing.Point(79, 110);
            this.butXem.Name = "butXem";
            this.butXem.Size = new System.Drawing.Size(60, 28);
            this.butXem.TabIndex = 2;
            this.butXem.Text = "Xem";
            this.butXem.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butXem.Click += new System.EventHandler(this.butXem_Click);
            // 
            // dgrXemLyLich
            // 
            this.dgrXemLyLich.AlternatingBackColor = System.Drawing.Color.LightGray;
            this.dgrXemLyLich.BackColor = System.Drawing.Color.Gainsboro;
            this.dgrXemLyLich.BackgroundColor = System.Drawing.Color.Silver;
            this.dgrXemLyLich.CaptionBackColor = System.Drawing.Color.LightSteelBlue;
            this.dgrXemLyLich.CaptionFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.dgrXemLyLich.CaptionForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrXemLyLich.CaptionText = "Thông Tin Nhân Viên";
            this.dgrXemLyLich.DataMember = "";
            this.dgrXemLyLich.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dgrXemLyLich.Location = new System.Drawing.Point(12, 175);
            this.dgrXemLyLich.Name = "dgrXemLyLich";
            this.dgrXemLyLich.Size = new System.Drawing.Size(272, 39);
            this.dgrXemLyLich.TabIndex = 13;
            this.dgrXemLyLich.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dgrXemLyLich_KeyDown);
            // 
            // label5
            // 
            this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label5.Location = new System.Drawing.Point(85, 65);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(56, 16);
            this.label5.TabIndex = 20;
            this.label5.Text = "Họ Tên:";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label4
            // 
            this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label4.Location = new System.Drawing.Point(24, 65);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(55, 16);
            this.label4.TabIndex = 19;
            this.label4.Text = "Mã NV: ";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txt_hoten
            // 
            this.txt_hoten.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txt_hoten.Location = new System.Drawing.Point(87, 83);
            this.txt_hoten.Name = "txt_hoten";
            this.txt_hoten.Size = new System.Drawing.Size(198, 21);
            this.txt_hoten.TabIndex = 1;
            this.txt_hoten.TextChanged += new System.EventHandler(this.txt_hoten_TextChanged);
            this.txt_hoten.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_hoten_KeyDown);
            this.txt_hoten.MouseHover += new System.EventHandler(this.txt_hoten_MouseHover);
            // 
            // txt_manv
            // 
            this.txt_manv.Enabled = false;
            this.txt_manv.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txt_manv.Location = new System.Drawing.Point(27, 83);
            this.txt_manv.Name = "txt_manv";
            this.txt_manv.Size = new System.Drawing.Size(60, 21);
            this.txt_manv.TabIndex = 0;
            this.txt_manv.Validated += new System.EventHandler(this.txt_manv_Validated);
            this.txt_manv.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_manv_KeyDown);
            this.txt_manv.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_manv_KeyPress);
            this.txt_manv.MouseHover += new System.EventHandler(this.txt_manv_MouseHover);
            // 
            // lst_lylich
            // 
            this.lst_lylich.ColumnCount = 0;
            this.lst_lylich.FormattingEnabled = true;
            this.lst_lylich.Location = new System.Drawing.Point(4, 117);
            this.lst_lylich.MatchBufferTimeOut = 1000;
            this.lst_lylich.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
            this.lst_lylich.Name = "lst_lylich";
            this.lst_lylich.Size = new System.Drawing.Size(75, 17);
            this.lst_lylich.TabIndex = 21;
            this.lst_lylich.TextIndex = -1;
            this.lst_lylich.TextMember = null;
            this.lst_lylich.ValueIndex = -1;
            this.lst_lylich.Visible = false;
            this.lst_lylich.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lst_lylich_KeyDown);
            // 
            // label1
            // 
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(24, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(238, 55);
            this.label1.TabIndex = 22;
            this.label1.Text = "IN LÝ LỊCH, QUÁ TRÌNH ĐÀO TẠO, GIA CẢNH";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // frmLyLichDaoTaoGiaCanh
            // 
            this.ClientSize = new System.Drawing.Size(290, 154);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.lst_lylich);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.txt_hoten);
            this.Controls.Add(this.txt_manv);
            this.Controls.Add(this.dgrXemLyLich);
            this.Controls.Add(this.butThoat);
            this.Controls.Add(this.butIn);
            this.Controls.Add(this.butXem);
            this.ForeColor = System.Drawing.Color.DarkBlue;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmLyLichDaoTaoGiaCanh";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Lý lịch";
            this.Load += new System.EventHandler(this.frmLyLichDaoTaoGiaCanh_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dgrXemLyLich)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void butThoat_Click(object sender, System.EventArgs e)
		{
			this.Close();
        }		

		private void dgrXemLyLich_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter)
				butXem.Focus();
		}

		private void butXem_Click(object sender, System.EventArgs e)
		{        
          	
                if (txt_manv.Text != "")
                {
                   
                
				print(false);
				DialogResult dr = MessageBox.Show(lan.Change_language_MessageText("Xem quá trình công tác của nhân viên này ?"),lan.Change_language_MessageText("Nhân Viên"),MessageBoxButtons.YesNo,MessageBoxIcon.Question);						
				if(dr == DialogResult.Yes) 			
				{
					print1(false);
				}
                DialogResult dr1 = MessageBox.Show(lan.Change_language_MessageText("Xem quá trình đào tạo của nhân viên này ?"),lan.Change_language_MessageText( "Nhân Viên"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);						
				if(dr1 == DialogResult.Yes) 			
				{
					print2(false);
				}
                DialogResult dr2 = MessageBox.Show(lan.Change_language_MessageText("Xem quan hệ gia đình của nhân viên này ?"),lan.Change_language_MessageText("Nhân Viên"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);						
				if(dr2 == DialogResult.Yes) 			
				{
					print3(false);
				}
           
			}
                else  MessageBox.Show(lan.Change_language_MessageText("Bạn chưa chọn nhân viên cần xem!"));
			

		}
		private int getSocon(string ma)
		{
            string sql1 = "SELECT count(gc.madt) AS socon FROM " + m_user + ".llnv AS l, " + m_user + ".giacanh AS gc";
			sql1+=" WHERE l.manv=gc.manv and gc.madt='C1' and l.manv='"+ma.Trim()+"'";
			if(mDB.get_data(sql1).Tables[0].Rows.Count!=0)
				return int.Parse(mDB.get_data(sql1).Tables[0].Rows[0][0].ToString());
			else
				return 0;
		}
		private void print(bool prn)
		{
            m_user = mDB.user;           
            try
            {
                string sql = "SELECT l.manv,trim(l.ho)||' '||trim(l.ten) as Hoten,l.phai as gioitinh,hd.sobhxh as SosoBHXH,";
                sql += " l.sold as solaodong,case when to_char(l.ngaysinh,'dd/mm/yyyy')<>'' then to_char(l.ngaysinh,'dd/mm/yyyy') else namsinh end as Ngaysinh,l.noisinh ,l.quequan as Nguyenquan,";
                sql += "  case when l.hoan_canh=1 then 'Có gia đình' else 'Chưa có gia đình' end as Tinhtranggiadinh,d.tendt as Dantoc,q.tenqg as Quoctich,t.tentg as Tongiao,";
                sql += " m.diengiai as Chucvu,trim(l.diachi)||', '||trim(g.tenquan)||', '||trim(f.tentt) as diachithuongtru,l.dienthoai as dien_thoai,hv.tenhv as tdhocvan,";
                sql += " ct.tenctdt as trinhdocm,hd.luonghd*(hd.hs_lc+hd.hs_cv) as mucluonghientai,gc.socon as socon,";//n.tennn as ngoaingu,n1.tennn as ngoaingu1,n2.tennn as ngoaingu2,n3.tennn as ngoaingu3,td.ten as tdnn,td1.ten as tdnn1,td2.ten as tdnn2,td3.ten as tdnn3
                sql += " l.cmndso as So_CMND,l.noicapcmnd as Noi_cap,to_char(l.cmndngay,'dd/mm/yyyy') as Ngay_cap,to_char(now(),'dd') AS Ngay, to_char(now(),'mm') AS Thang, to_char(now(),'yyyy') AS Nam,";
                sql += " trim(l.noio)||', '||trim(g.tenquan)||', '||trim(f.tentt) as noiohiennay,";
                sql += " case when l.chinhtri='CC' then 'Cao cấp' when l.chinhtri='CN' then 'Cử nhân' when l.chinhtri='TC' then 'Trung cấp' when l.chinhtri='SC' then 'Sơ cấp' else '' end as tdchinhtri,";
                sql += " th.ten as vitinh";
               

                sql += " ,case when l.mann <> '' then trim(n.tennn)||'_'||trim(td.ten)  else '' end as ngoaingu";
                sql += " ,case when l.mann1 <> '' then trim(n1.tennn)||'_'||trim(td1.ten) else '' end as ngoaingu1";
                sql += " ,case when l.mann2 <> '' then trim(n2.tennn)||'_'||trim(td2.ten)  else '' end as ngoaingu2";
                sql += " ,case when l.mann3 <> '' then trim(n3.tennn)||'_'||trim(td3.ten) else '' end as ngoaingu3,";
                //
                sql += " hd.sobhxh,to_char(l.dubi_dang,'dd/mm/yyyy') as ngaydubi,to_char(l.cthuc_dang,'dd/mm/yyyy') as ngaycthuc,";
                sql += " to_char(hd.vao_cdoan,'dd/mm/yyyy') as ngaycdoan,ql.ten as qlnn, ";//case when hd.tdqlnn='02' then 'Sơ cấp' when hd.tdqlnn='03' then 'Trung cấp' else '' end
                sql += " to_char(hd.ngaydenct,'dd/mm/yyyy') as ngayct, to_char(hd.ngayhd,'dd/mm/yyyy') as ngaybc, ";
                sql += " case when hd.loaihd='BC' then to_char(hd.ngayhd,'dd/mm/yyyy') else to_char(hd.ngaydenct,'dd/mm/yyyy') end as ngaybienche,'' as str_ngoaingu";
                sql += " FROM  " + m_user + ".llnv l inner join " + m_user + ".hopdong hd on l.manv=hd.manv";
                sql += " left join " + m_user + ".tdqlnn ql on hd.tdqlnn=ql.ma";
                sql += " left join " + m_user + ".tdnnth td on td.ma=l.tdnn";
                sql += " left join " + m_user + ".tdnnth th on l.tdth=th.ma";
                sql += " left join " + m_user + ".tdnn1 td1 on td1.ma=l.tdnn1 ";
                sql += " left join " + m_user + ".tdnn2 td2 on td2.ma=l.tdnn2";
                sql += " left join " + m_user + ".tdnn3 td3 on td3.ma=l.tdnn3";
                sql += " left join " + m_user + ".ngoaingu n on l.mann=n.mann ";
                sql += " left join " + m_user + ".ngoaingu_1 n1 on l.mann1=n1.mann";
                sql += " left  join " + m_user + ".ngoaingu_2 n2 on l.mann2=n2.mann";
                sql += " left  join " + m_user + ".ngoaingu_3 n3 on l.mann3=n3.mann";

                sql += " left join " + m_user + ".dmcv m on hd.macv=m.macv";
                sql += " left join " + m_user + ".dantoc d on l.madt=d.madt";
                sql += " left join " + m_user + ".btdtt f on l.t_diachi=f.matt";
                sql += " left join " + m_user + ".btdquan g on l.h_noio=g.maqu";
                sql += " left join " + m_user + ".quocgia q on l.maqg=q.maqg";
                sql += " left join " + m_user + ".tongiao t on l.matgiao=t.matgiao";
                sql += " left join " + m_user + ".hocvan hv on l.mahv=hv.mahv";
                sql += " left join " + m_user + ".ctdaotao ct on l.nnghiep=ct.mactdt";
                sql += " left join " + m_user + ".gcanh_con gc on gc.manv=l.manv";
                sql += " inner join " + m_user + ".max_lan ml on hd.manv=ml.manv";
                sql += " WHERE hd.ngaynghi is null and hd.lan=ml.lan ";
                if (txt_manv.Text != "")
                         sql+=" and l.manv='"+ txt_manv.Text.Trim()+"'";
                dsxml = mDB.get_data(sql);

                dsxml.WriteXml("..\\xml\\h_lylichCTDTGD.xml", XmlWriteMode.WriteSchema);
                if (dsxml.Tables[0].Rows.Count != 0)
                {

                    frmReport f = new frmReport(mDB, dsxml,lan.Change_language_MessageText("LÝ LỊCH TRÍCH NGANG"), "h_lylichCTDTGD.rpt", false, user_dn);
                    f.ShowDialog(this);
                }
                else
                    MessageBox.Show(lan.Change_language_MessageText("Chưa có đầy đủ dữ liệu"),lan.Change_language_MessageText("Thông Báo"));
            }
            catch { }
		}

		private void print1(bool prn)
		{
            m_user = mDB.user;
			try
			{
				string sql="SELECT trim(l.ho)||' '||l.ten as Hoten,";
				sql+=" to_char(cv.ngayhl,'dd/mm/yyyy') as Tungayct,cv.ndcv ,mh.tenhd,cv.ngayhl ,";
                sql += " cv.mucluong,cv.donvi,case when to_char(cv.denngay,'dd/mm/yyyy') <>'' and dennam='' then to_char(cv.denngay,'dd/mm/yyyy') ";
                sql += " when to_char(cv.denngay,'dd/mm/yyyy') is null and dennam <>'' then dennam ";
                sql += " when to_char(cv.denngay,'dd/mm/yyyy') is null and dennam ='' then 'Hiện tại' else to_char(cv.denngay,'dd/mm/yyyy') end as denngay";
                sql += " from " + m_user + ".llnv l inner join " + m_user + ".hopdong hd on l.manv=hd.manv ";
                sql += " left join " + m_user + ".congviec cv on  cv.manv=l.manv ";
                sql += " left join " + m_user + ".mahd mh on hd.loaihd=mh.mahd";
                sql += " inner join "+m_user+".max_lan ml on hd.manv=ml.manv";
				if (txt_manv.Text!="") sql+=" where l.manv='"+txt_manv.Text.Trim()+"'";
                sql += " and hd.lan=ml.lan order by ngayhl";
				ds=mDB.get_data(sql);
                ds.WriteXml("..\\xml\\h_lylichcongtac.xml", XmlWriteMode.WriteSchema);
				if (ds.Tables[0].Rows.Count>0)
				{
                    frmReport f = new frmReport(mDB, ds,lan.Change_language_MessageText("LÝ LỊCH TRÍCH NGANG"), "h_lylichcongtac.rpt", false, user_dn);
					f.ShowDialog(this);					
				}
				else
					MessageBox.Show(lan.Change_language_MessageText("Nhân viên này chưa đi công tác"),lan.Change_language_MessageText("Thông Báo"));
			}
			catch{}
		}

		private void print2(bool prn)
		{
            m_user = mDB.user;
			try
			{
				string sql="SELECT trim(l.ho)||' '||l.ten as HOTEN,";
				sql += " to_char(qt.tungay,'dd/mm/yyyy') as TUNGAY,case when to_char(qt.denngay,'dd/mm/yyyy') <>'' and dennam='' then to_char(qt.denngay,'dd/mm/yyyy') ";
                sql += " when to_char(qt.denngay,'dd/mm/yyyy') is null and dennam <>'' then dennam ";
                sql += " when to_char(qt.denngay,'dd/mm/yyyy') is null and dennam ='' then 'Hiện tại' else to_char(qt.denngay,'dd/mm/yyyy') end as denngay,";
                sql += " he.tenhe as HINHTHUC,ct.tenctdt as NGANHNHE,b.tenbang as TRINHDO,qt.ghichu,qt.noi_dt,qt.tungay as tn";
                sql += " FROM " + m_user + ".llnv l inner join " + m_user + ".hopdong hd on l.manv=hd.manv";                
                sql += " left join " + m_user + ".qtdaotao qt on l.manv=qt.manv";
                sql += " left join " + m_user + ".hedaotao he on qt.hehocvan=he.mahe";
                sql += " left join " + m_user + ".ctdaotao ct on qt.mahv=ct.mactdt";
                sql += " left join " + m_user + ".bangcap b on qt.mabangcap=b.mabangcap ";
                sql += " inner join "+m_user+".max_lan ml on hd.manv=ml.manv";
				sql+=" WHERE hd.ngaynghi is null and hd.lan=ml.lan";				
				if (txt_manv.Text!="") 
                    sql+=" and l.manv='"+txt_manv.Text.Trim()+"'";
                sql += " order by tn";	
                ds=mDB.get_data(sql);
                ds.WriteXml("..\\xml\\h_lylichdaotao.xml", XmlWriteMode.WriteSchema);
				
				if (ds.Tables[0].Rows.Count>0)
				{
                    frmReport f = new frmReport(mDB, ds, lan.Change_language_MessageText("LÝ LỊCH TRÍCH NGANG"), "h_lylichdaotao.rpt", false, user_dn);
					f.ShowDialog(this);					
				}
				else
					MessageBox.Show(lan.Change_language_MessageText("Chưa có dữ liệu về quá trình đào tạo của nhân viên này"),lan.Change_language_MessageText("Thông Báo"));
			}
			catch{}
		}

		private void print3(bool prn)
		{
            m_user = mDB.user;
			try
			{
				string sql=" SELECT trim(l.ho)||' '||l.ten as hoten,";
				sql+=" dt.tendt as quanhe,g.htendtg as hotenquanhe,";
				sql+=" g.namsinh as namsinh,g.ghichu as ghichu,g.quequan,g.nghenghiep,g.phai";
                sql += " FROM " + m_user + ".llnv l inner join " + m_user + ".hopdong hd on l.manv=hd.manv";
                sql += " inner join " + m_user + ".giacanh g on l.manv=g.manv";
                sql += " left join " + m_user + ".doituong dt on g.madt=dt.madt";
                sql += " inner join "+m_user+".max_lan ml on hd.manv=ml.manv";                
                sql+=" WHERE hd.ngaynghi is null and hd.lan=ml.lan";
                if (txt_manv.Text!="") 
                    sql+=" and l.manv='"+ txt_manv.Text.Trim()+"'";
                sql += " order by dt.madt";
                ds=mDB.get_data(sql);
                ds.WriteXml("..\\xml\\h_lylichgiacanh.xml", XmlWriteMode.WriteSchema);
				if (ds.Tables[0].Rows.Count>0)
				{
                    frmReport f = new frmReport(mDB, ds,lan.Change_language_MessageText("LÝ LỊCH TRÍCH NGANG"), "h_lylichgiacanh.rpt", true, user_dn);
					f.ShowDialog(this);					
				}
				else
					MessageBox.Show(lan.Change_language_MessageText("Chưa có thông tin về gia cảnh của nhân viên này"),lan.Change_language_MessageText("Thông Báo"));
			}
			catch{}
		}

		private void butIn_Click(object sender, System.EventArgs e)
		{
			try
			{
				print(true);
				DialogResult dr = MessageBox.Show(lan.Change_language_MessageText("In quá trình công tác của nhân viên này ?"),lan.Change_language_MessageText("Nhân Viên"),MessageBoxButtons.YesNo);						
				if(dr == DialogResult.Yes) 			
				{
					print1(true);
				}
				DialogResult dr1 = MessageBox.Show(lan.Change_language_MessageText("In quá trình đào tạo của nhân viên này ?"),lan.Change_language_MessageText("Nhân Viên"),MessageBoxButtons.YesNo);						
				if(dr1 == DialogResult.Yes) 			
				{
					print2(true);
				}
				DialogResult dr2 = MessageBox.Show(lan.Change_language_MessageText("In quan hệ gia đình của nhân viên này ?"),lan.Change_language_MessageText("Nhân Viên"),MessageBoxButtons.YesNo);						
				if(dr2 == DialogResult.Yes) 			
				{
					print3(true);
				}
			}
			catch{}
		}
		private void load_hoten()
		{
           
               ds_lst = TenNV();               
                lst_lylich.DataSource = ds_lst.Tables[0];
                lst_lylich.DisplayMember = "manv";
                lst_lylich.ValueMember = "hoten";
                
        
		}    
       private void frmLyLichDaoTaoGiaCanh_Load(object sender, System.EventArgs e)
		{
            txt_hoten.Focus();                          
            load_hoten();
           
           
		}     
        DataSet Ten_NV(string madv)
        {
            return mDB.get_data("SELECT manv,ho||' '||ten AS hoten" +
                " FROM "+mDB.user+".llnv WHERE madv ='" + madv + "' order by manv");
        }       
        private DataSet TenNV()
        {
            //return mDB.get_data("SELECT manv,ho||' '||ten AS hoten from "+mDB.user+".llnv order by manv");
            string sql = "SELECT manv,ho||' '||ten AS hoten from " + mDB.user + ".llnv order by manv";
            return mDB.get_data(sql);
          
        }
        private void lst_lylich_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
              
                txt_manv_Validated(null,null);
            }
        }
        
      

        private void txt_hoten_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Down) || (e.KeyCode == Keys.Up))
            {
                this.lst_lylich.Focus();
            }
            else if (e.KeyCode == Keys.Return)
            {
                if (this.lst_lylich.Visible)
                {
                    this.lst_lylich.Focus();
                }
                else
                {
                    SendKeys.Send("{Tab}");
                }
            }
        }
        private void loc_hoten(string hoten)
        {
            try
            {
                CurrencyManager cm = (CurrencyManager)this.BindingContext[lst_lylich.DataSource];
                DataView dv = (DataView)cm.List;
                dv.RowFilter = "hoten like '%" + hoten.Trim() + "%' ";
            }
            catch
            {

            }
        }
        
        private void txt_hoten_TextChanged(object sender, EventArgs e)
        {
            if (this.ActiveControl == this.txt_hoten)
            {
                this.loc_hoten(txt_hoten.Text.Trim());
                this.lst_lylich.BrowseToTennv(txt_hoten, txt_manv,txt_hoten,500);
            }
            
        }

        private void txt_manv_MouseHover(object sender, EventArgs e)
        {
            ToolTip tl_manv = new ToolTip();
            tl_manv.ShowAlways = true;
            tl_manv.SetToolTip(txt_manv,lan.Change_language_MessageText( "Nhập mã nhân viên cần xem chỉ nhập số !"));

        }

        private void txt_hoten_MouseHover(object sender, EventArgs e)
        {
            ToolTip tl_manv = new ToolTip();
            tl_manv.ShowAlways = true;
            tl_manv.SetToolTip(txt_hoten,lan.Change_language_MessageText( "Nhập tên nhân viên cần xem !"));
        }

        //private void txt_manv_TextChanged(object sender, EventArgs e)
        //{
        //    if (this.ActiveControl == this.txt_manv)
        //    {
        //        this.loc_manv(txt_manv.Text.Trim());
        //        this.lst_lylich.BrowseToTennv(txt_manv,txt_hoten,txt_hoten, 500);
        //    }
        //}

        private void txt_manv_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Down) || (e.KeyCode == Keys.Up))
            {
                this.lst_lylich.Focus();
            }
            else if (e.KeyCode == Keys.Return)
            {
                if (this.lst_lylich.Visible)
                {
                    this.lst_lylich.Focus();
                }
                else
                {
                    SendKeys.Send("{Tab}");
                }
            }
        }
        private bool IsNumeric(string strNum)
        {
            int iNum;
            try
            {
                iNum = int.Parse(strNum);
                return true;
            }
            catch
            {
                return false;
            }
        }
        private void txt_manv_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!IsNumeric(e.KeyChar.ToString()))
                e.Handled = true;
            if (e.KeyChar == 8 || e.KeyChar == '.')
                e.Handled = false;
        }
        DataRow[] dr_lylich;
        private void txt_manv_Validated(object sender, EventArgs e)
        {
            if (txt_manv.Text.Trim() != "")
            {
                this.dr_lylich = ds_lst.Tables[0].Select("manv='" + txt_manv.Text.Trim() + "'");
                if (dr_lylich != null)
                {
                    txt_hoten.Text = dr_lylich[0]["hoten"].ToString().Trim();
                }
                else
                {
                    txt_hoten.Text = "";
                }
            }
        }

      
        
       

	}
}
